package org.lib.mongodbhello;

import java.util.Arrays;
import java.util.function.Consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class MongodbHelloApplication {

	private static Consumer<Object> cs = System.out::println;
	
	public static void main(String[] args) {
		ConfigurableApplicationContext ctx = SpringApplication.run(MongodbHelloApplication.class, args);

		// 调试用
//		studyContext(ctx);
	}
	
	public static void studyContext(ConfigurableApplicationContext ctx) {
		cs.accept("++++++studyContext++++++\nBeanDefinitionCount=" + ctx.getBeanDefinitionCount());
		String[] beanNames = ctx.getBeanDefinitionNames();
		cs.accept("beanNames.length=" + beanNames.length);
		cs.accept("输出Bean的名称：");
		Arrays.stream(beanNames).forEach((name)->{
			cs.accept("name=" + name);
		});
		
//		cs.accept("---");
//		Arrays.stream(beanNames).forEach((name)->{
//			cs.accept(String.format("name=%s, bean=%s", name, ctx.getBean(name).toString()));
//		});
		
		cs.accept("------studyContext------");
	}

}
